using UnityEngine;
using System.Collections;

/// <summary>
/// Manage a single bloc : move it and destroy it when out of screen.
/// </summary>
public class MovingElement: MonoBehaviour 
{
	protected void Start()
	{
		if(rigidbody == null)
			gameObject.AddComponent<Rigidbody>().isKinematic = true;
	}
	
	protected void FixedUpdate()
	{
		//transform.position -= Vector3.right * LevelGenerator.sSpeed * Time.deltaTime;
		
		rigidbody.MovePosition(rigidbody.position - Vector3.right * LevelGenerator.sSpeed * Time.fixedDeltaTime);
	}
	
	void OnBecameInvisible()
	{
		if(transform.position.x < 0)
			Destroy(gameObject);
	}
}
